package com.xiliu.server.modules.basicdata.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiliu.common.annotation.Log;
import com.xiliu.common.controller.BaseController;
import com.xiliu.common.enums.BusinessType;
import com.xiliu.common.page.TableDataInfo;
import com.xiliu.common.result.R;
import com.xiliu.server.modules.basicdata.entity.XlHouseConfig;
import com.xiliu.server.modules.basicdata.service.IXlHouseConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 房源配套配置表Controller
 * 
 * @author xiliu
 * @date 2022-11-11
 */
@RestController
@RequestMapping("/basic/config")
public class XlHouseConfigController extends BaseController {
    @Autowired
    private IXlHouseConfigService xlHouseConfigService;

    /**
     * 查询房源配套配置表列表
     */
    @PreAuthorize("@customSs.hasPermi('basic:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlHouseConfig xlHouseConfig) {
        startPage();
        List<XlHouseConfig> list = xlHouseConfigService.selectXlHouseConfigList(xlHouseConfig);
        return getDataTable(list);
    }

    /**
     * 获取房源配套配置表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('basic:config:query')")
    @GetMapping(value = "/{houseConfigId}")
    public R getInfo(@PathVariable("houseConfigId") Long houseConfigId) {
        return R.ok(xlHouseConfigService.selectXlHouseConfigByHouseConfigId(houseConfigId));
    }

    /**
     * 新增房源配套配置表
     */
    @PreAuthorize("@customSs.hasPermi('basic:config:create')")
    @Log(title = "房源配套配置表", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody XlHouseConfig xlHouseConfig) {
        boolean success = xlHouseConfigService.create(xlHouseConfig);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改房源配套配置表
     */
    @PreAuthorize("@customSs.hasPermi('basic:config:edit')")
    @Log(title = "房源配套配置表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{houseConfigId}")
    public R update(@PathVariable Long houseConfigId,  @RequestBody XlHouseConfig xlHouseConfig) {
        xlHouseConfig.setHouseConfigId(houseConfigId);
        boolean success = xlHouseConfigService.update(xlHouseConfig);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除房源配套配置表
     */
    @PreAuthorize("@customSs.hasPermi('basic:config:remove')")
    @Log(title = "房源配套配置表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseConfigIds}")
    public R remove(@PathVariable Long[] houseConfigIds) {
        return R.ok(xlHouseConfigService.deleteXlHouseConfigByHouseConfigIds(houseConfigIds));
    }

    @GetMapping("/get-all-list")
    public R getAlllist() {
        List<XlHouseConfig> list = xlHouseConfigService.list(new LambdaQueryWrapper<XlHouseConfig>().eq(XlHouseConfig::getIsShow,1));
        return R.ok(list);
    }
}
